<template>
  <div>
    <div class="container">
      <div class="left">
        <div class="titleName">冰雪之恋</div>
        <div class="titleSecond">今日精选推荐</div>
        <div class="buy" @click="BuyHandle">立即购买</div>

      </div>
      <div class="right">
        <img src="https://p1-cdn-holiland.1900m.com/pc_ad/202302/24/4a1677208519b3388.png" alt="">
      </div>
    </div>
    <div class="hot">
      <div class="titlee">
        <el-tag type="danger" style="width: 100%; font-size: 20px;">热销推荐</el-tag>
        <div class="boxx">
          <ul>
            <li v-for="(item,index) in category" :key="index">
              <div class="image">
                <img :src="item.imgUrl" alt="">
                <div class="detailTips">
                  <span style="color: #fff;margin-left: 20px;" @click="goToDetail(item.id)">查看详情</span>
                  <span class="buyButton" @click="buy(item.id)">立即购买</span>
                </div>
              </div>
              <div class="cakeName">{{item.cakeName}}</div>
              <div class="cakePrice">￥{{item.price/100}}</div>
            </li>
          </ul>
        </div>
      </div>
      <div class="titlee">
        <el-tag type="warning" style="width: 100%; font-size: 20px;">热销推荐</el-tag>
        <div class="boxx">
          <ul>
            <li v-for="(item,index) in category" :key="index">
              <div class="image">
                <img :src="item.imgUrl" alt="">
                <div class="detailTips">
                  <span style="color: #fff;margin-left: 20px;">查看详情</span>
                  <span class="buyButton" @click="buy(item.id)">立即购买</span>
                </div>
              </div>
              <div class="cakeName">{{item.cakeName}}</div>
              <div class="cakePrice">￥{{item.price/100}}</div>
            </li>
          </ul>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getTabs,addCake } from '@/api/index'
export default {
  data() {
    return {
      category:[],
      pageNum:1,
      pageSize:5
    }
  },
  methods: {
    BuyHandle() {
      let param = {
        cakeId:'1703939059505778692',
        count:1
      }
      addCake(param).then(res => {
        this.$message({
          type:'success',
          message:'添加成功'
        })
      })
    },
    goToDetail(id) {
        this.$router.push({
          path:'/detail',
          query:{
            id
          }
        })
      },
    buy(id) {
      let param = {
        cakeId:id,
        count:1
      }
      addCake(param).then(res => {
        this.$message({
          type:'success',
          message:'添加成功！'
        }).catch(err =>{
          this.$message({
            type:'error',
            message:'添加失败，请检查网络'
          })
        })
      })
    },
    getCatory(){
     
      getTabs(this.pageNum,this.pageSize).then((res) => {
        this.category = res.data.records
      })
    }
  },
  mounted() {
    this.getCatory()
  }
}
</script>

<style scoped lang="less">
.container {
  border-radius: 15px;
  background-color: #fff6ee;
  display: flex;
  flex-direction: row;
  justify-content: space-around;
  /* width: 1200px; */
  height: 300px;
  padding: 30px;
  .left {
    width: 50%;
    height: 100px;
    align-items: center;
    flex-direction: row;
    justify-content: space-between;
    .titleName {
      color: #409eff;
      font-size: 60px;
      font-weight: bold;
      height: 100px;
    }
    .titleSecond {
      color: #ffd690;
      font-size: 20px;
      font-weight: bold;
      height: 100px;
    }
    .buy {
      display: flex;
      justify-content: center;
      align-items: center;
      width: 200px;
      height: 45px;
      border: 5px solid #409eff;
      color: #409eff;
      font-size: 20px;
      cursor: pointer;
    }
   
  }
  .right{
      width: 580px;
      height: 300px;
      overflow: hidden;;
    }
}
.hot {
  margin-top: 30px;
  .image img {
    width: 100%;
    height: 280px;
  }
  .titlee {
    margin-bottom: 30px;
  }
  .boxx ul {
    width: 100%;
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: space-between;
    li {
      width: 23%;
      // margin: 1px;
      margin-top: 10px;
      margin-left: 3px;
      .image {
        cursor: pointer;
        position: relative;
        .detailTips {
          display: none;
          width: 100%;
          height: 50px;
          position: absolute;
          bottom: 0;
          background: rgba(0, 0, 0, 0.75);
          line-height: 50px;
          font-size: 14px;
          .buyButton{
            margin-top: 10px;
            margin-right: 20px;
            float: right;
            display: flex;
            justify-content: center;
            align-items: center;
            color: #fff;
            border: 1px solid #fff;
            width: 100px;
            height: 30px;
          }
        }
      }
      .image:hover .detailTips {
        display: block;
        cursor: pointer;
      }
      
      .cakeName {
        font-size: 16px;
        font-weight: bold;
        margin: 5px 0;
      }
      .cakePrice {
        color: red;
        font-size: 32px;
      }
    }
  }
}
</style>